package com.woniu.his.mms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.mms.client.HerbalPrescriptionClient;
import com.woniu.his.mms.client.param.CreateHerbalPrescriptionClientParam;
import com.woniu.his.mms.client.result.HerbalPrescriptionResult;
import com.woniu.his.mms.service.HerbalPrescriptionRecordService;
import com.woniu.his.mms.service.dto.HerbalPrescriptionDto;
import com.woniu.his.mms.service.param.CreateHerbalPrescriptionParam;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version: java version 1.8
 * @Author: ZJH
 * @description:
 * @date: 2022-11-28 15:26
 */
@RestController
@RequestMapping("mms")
@Slf4j
public class HerbalPrescriptionApiImpl implements HerbalPrescriptionClient {

    @Resource
    private HerbalPrescriptionRecordService herbalPrescriptionRecordService;

    @Override
    public Result<Boolean> createHerbalPrescription(CreateHerbalPrescriptionClientParam param) {
        log.info("创建草药处方参数：{}",param);
        CreateHerbalPrescriptionParam createHerbalPrescriptionParam = BeanUtil.copyProperties(param, CreateHerbalPrescriptionParam.class);
        Boolean bool = herbalPrescriptionRecordService.createHerbalPrescription(createHerbalPrescriptionParam);
        return Result.getInstance(Boolean.class).setData(bool);
    }

    @Override
    public Result<Boolean> deleteHerbalPrescription(List<Long> ids) {
        log.info("作废草药处方参数：{}",ids);
        Boolean bool = herbalPrescriptionRecordService.deleteHerbalPrescription(ids);
        return Result.getInstance(Boolean.class).setData(bool);
    }

    @Override
    public Result<List<HerbalPrescriptionResult>> queryHerbalPrescriptionByIds(List<Long> ids) {
        log.info("查询草药处方参数ids：{}",ids);
        List<HerbalPrescriptionDto> herbalPrescriptionDtos = herbalPrescriptionRecordService.queryHerbalPrescriptionByIds(ids);
        List<HerbalPrescriptionResult> prescriptionResults = BeanUtil.copyToList(herbalPrescriptionDtos, HerbalPrescriptionResult.class);
        return Result.getInstanceList(HerbalPrescriptionResult.class).setData(prescriptionResults);
    }

    @Override
    public Result<HerbalPrescriptionResult> queryHerbalPrescriptionByCaseId(Long CaseId) {
        log.info("查询草药处方参数CaseId：{}",CaseId);
        HerbalPrescriptionDto dtos = herbalPrescriptionRecordService.queryHerbalPrescriptionByCaseId(CaseId);
        HerbalPrescriptionResult prescriptionResults = BeanUtil.copyProperties(dtos, HerbalPrescriptionResult.class);
        return Result.getInstance(HerbalPrescriptionResult.class).setData(prescriptionResults);
    }

    @Override
    public Result<HerbalPrescriptionResult> queryHerbalPrescriptionByBillId(Long billId) {
        log.info("根据账单id查询草药处方：{}",billId);
        HerbalPrescriptionDto herbalPrescriptionDto = herbalPrescriptionRecordService.queryHerbalPrescriptionByBillId(billId);
        HerbalPrescriptionResult herbalPrescriptionResult = BeanUtil.copyProperties(herbalPrescriptionDto, HerbalPrescriptionResult.class);
        return Result.getInstance(HerbalPrescriptionResult.class).setData(herbalPrescriptionResult);
    }

    @Override
    public Result<Boolean> paySuccess(Long billId) {
        log.info("支付成功修改状态参数：{}",billId);
        Boolean bool = herbalPrescriptionRecordService.paySuccess(billId);
        return Result.getInstance(Boolean.class).setData(bool);
    }
}
